package NC;

import java.util.HashMap;
import java.util.Map;

public class NC73 {
    public int MoreThanHalfNum_Solution(int [] array) {
        int len = array.length;
        HashMap<Integer,Integer> ans = new HashMap<>();
        for (int i = 0; i < len; i++) {
            ans.put(array[i],ans.get(array[i])==null?1:ans.get(array[i])+1);
        }
        for(Map.Entry<Integer,Integer> entry:ans.entrySet()){
            if(entry.getValue()>len/2) return entry.getKey();
        }
        return 0;
    }
}
